const seq = require('@db/seq');
const { string, integer, text } = require('@db/types');
const { verification } = require('@db/verification')
const { DEFAULT_PICTURE } = require('@config/constant')
const model = {
    account: {
        type: string,
        allowNull: false,
        comment: '账号',
        verification: 'string',
    },
    userName: {
        type: string,
        allowNull: false,
        comment: '用户名',
        verification: 'string',
    },
    password: {
        allowNull: false,
        comment: '密码',
        type: string,
        verification: 'string',
    },
    avatar: {
        allowNull: true,
        comment: '头像',
        defaultValue: DEFAULT_PICTURE,
        type: text,
        verification: 'string',
    },
    loginTime: {
        allowNull: true,
        comment: '最后登录时间',
        defaultValue: '',
        type: string,
        verification: 'string',
    },
    status: {
        allowNull: true,
        comment: '用户状态',
        defaultValue: 1101, // 1101启用 1102禁用
        type: integer,
        verification: 'number',
    }
}

const verifiAdminUser = (data, exclude = []) => {
    return verification(data, model, exclude);
}

// 后台用户表
const AdminUser = seq.define('adminUser', model, {
    timestamps: true,
    paranoid: true
});

module.exports = {
    AdminUser,
    verifiAdminUser
};
